package com.cloud.drore.eboss.supplier.service.impl;

import com.cloud.drore.eboos.common.base.*;
import com.cloud.drore.eboos.common.base.Dictionary;
import com.cloud.drore.eboos.common.constant.ResultCodeConstant;
import com.cloud.drore.eboos.common.entity.base.DictionaryVo;
import com.cloud.drore.eboos.common.entity.supplier.ProductRelation;
import com.cloud.drore.eboos.common.entity.supplier.po.CombinationProductQueryPo;
import com.cloud.drore.eboos.common.entity.supplier.po.TicketQueryPo;
import com.cloud.drore.eboos.common.entity.supplier.vo.CombinationProductVo;
import com.cloud.drore.eboos.common.entity.supplier.vo.ConsumeAndPoiNameVo;
import com.cloud.drore.eboos.common.entity.supplier.vo.TicketAllVo;
import com.cloud.drore.eboos.common.util.CodingGeneration;
import com.cloud.drore.eboos.common.util.LocalData;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.operation.entity.ConsumeOperation;
import com.cloud.drore.eboss.operation.entity.POIOperation;
import com.cloud.drore.eboss.operation.supplierApiService.IConsumeSupplierApiService;
import com.cloud.drore.eboss.operation.supplierApiService.IPOISupplierApiService;
import com.cloud.drore.eboss.supplier.entity.*;
import com.cloud.drore.eboss.supplier.entity.vo.CombProSupplierVo;
import com.cloud.drore.eboss.supplier.entity.vo.DictionaryTicketVo;
import com.cloud.drore.eboss.supplier.mapper.*;
import com.cloud.drore.eboss.supplier.operationApiService.ICombinationProductOperationApiService;
import com.cloud.drore.eboss.supplier.service.IBaseDataFeign;
import com.cloud.drore.eboss.supplier.service.ICombinationProductService;
import com.cloud.drore.eboss.supplier.service.IDistributorProductAssociationService;
import com.cloud.drore.eboss.supplier.service.IProductStockService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static com.cloud.drore.eboos.common.constant.CommonConstant.TICKET_PRODUCT_CH_NAME;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/8 14:47 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
@Service
public class CombinationProductServiceImpl extends BaseServiceImpl implements ICombinationProductService,ICombinationProductOperationApiService {

    @Autowired
    CombinationProductRelationMapper combinationProductRelationMapper;
    @Autowired
    CombinationProductMapper combinationProductMapper;
    @Autowired
    ProductRelationMapper productRelationMapper;
    @Autowired
    CombinationProductStockMapper combinationProductStockMapper;
    @Autowired
    CombinationProductPriceMapper combinationProductPriceMapper;
    @Resource
    IConsumeSupplierApiService consumeSupplierApiService;
    @Autowired
    TicketMapper ticketMapper;
    @Autowired
    IBaseDataFeign baseDataFeign;
    @Resource
    IPOISupplierApiService ipoiSupplierApiService;
    @Autowired
    ProductConsumeRelationMapper productConsumeRelationMapper;
    @Autowired
    ProductValidateMethodMapper productValidateMethodMapper;
    @Autowired
    CollocationProductMapper collocationProductMapper;
    @Resource
    IDistributorProductAssociationService distributorProductAssociationService;
    @Autowired
    ProductRejectInfoMapper productRejectInfoMapper;
    @Resource
    IProductStockService productStockService;
    @Autowired
    ProductStockMapper productStockMapper;

    private Logger log = LoggerFactory.getLogger(CombinationProductServiceImpl.class);

    static final String PRODUCT_UPDATE_SUCESS = "组合产品信息更新成功!";
    static final String PRODUCT_UPDATE_FAILURE = "组合产品信息更新失败!";
    static final String PRODUCT_QUERY_FAILURE = "组合产品信息查询失败!";
    static final String PRODUCT_SAVE_FAILURE = "组合产品信息保存失败!";
    static final String COMBINATION_PRODUCT = "COMBINATION_PRODUCT";
    static final String TICKET_PRODUCT  = "TICKET_PRODUCT";
    static final String DICTIONARY_STATUS_TRUE  = "1";
    static final String DICTIONARY_STATUS_FALSE  = "0";
    static final String TO_BE_AUDITED  = "TO_BE_AUDITED";
    static final String OFF_THE_SHELF ="OFF_THE_SHELF";
    static final String PRODUCT_NUM_PREFIX ="TP";
    static final String THE_SHELVES = "THE_SHELVES";
    static final String UNLIMITED_STOCK = "UNLIMITED_STOCK";
    private static String CYCLICAL_INVENTORY = "CYCLICAL_INVENTORY";
    private static String EXPIRED = "EXPIRED";

    @Override
    public MyMapper getMapper() {
        return combinationProductMapper;
    }

    /**
     * @ClassName: CombinationProductServiceImpl
     * @param combinationProduct
     * @param prices
     * @param stocks
     * @param combinationProductRelationList
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 保存组合产品
     * @CreateDate: Created in 2018/1/26 15:32
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED,rollbackFor=Exception.class)
    public ResultMessage saveCombinationProduct(CombinationProduct combinationProduct, List<CombinationProductPrice> prices,
                                                List<CombinationProductStock> stocks, List<CombinationProductRelation> combinationProductRelationList) throws BusinessException{
        ResultMessage rs = new ResultMessage();
        //设置待审核状态
        combinationProduct.setStatus(TO_BE_AUDITED);
        //设置商户id
        combinationProductMapper.insertUseGeneratedKeys(combinationProduct);
        //设置产品编号
        combinationProduct.setProductNum(CodingGeneration.getProductGenerationCodingNum(COMBINATION_PRODUCT,combinationProduct.getId()));
        combinationProductMapper.updateCombinationProductByParam(combinationProduct);
        //组合产品复选框类型保存
        saveVerificationCodeTypeAndCollocation(combinationProduct);

        //保存组合产品库存
        if(stocks!=null && stocks.size()>0){
            //保存库存
            for (CombinationProductStock stock : stocks){
                stock.setCombinationProductId(combinationProduct.getId());
                combinationProductStockMapper.insertUseGeneratedKeys(stock);
            }
        }

        //保存到公共产品关联表
        ProductRelation productRelation = new ProductRelation();
        //设置公共产品参数
        productRelation.setProductId(combinationProduct.getId());
        productRelation.setInstruction(combinationProduct.getInstruction());
        productRelation.setCrowd(combinationProduct.getProductCrowd());
        //设置组合产品类型
        productRelation.setProductType(COMBINATION_PRODUCT);
        productRelation.setProductName(combinationProduct.getProductName());
        productRelation.setStatus(combinationProduct.getStatus());
        productRelation.setStockMethod(combinationProduct.getStockMethod());
        productRelation.setPaymentType(combinationProduct.getPaymentType());
        productRelation.setRefundModel(combinationProduct.getRefundModel());
        productRelation.setRefundFee(combinationProduct.getRefundFee());
        productRelation.setProductNum(combinationProduct.getProductNum());
        //设置商户id
        productRelation.setMerchantId(Long.valueOf(LocalData.getCurrentUser().getTypeId()));
        productRelationMapper.insert(productRelation);

        //需要从前端接收产品类型
        BigDecimal totalPrice = BigDecimal.ZERO;
        //是否实名制
        int isRealName = 0;
        Date termOfValidityStartTime = null;
        Date termOfValidityEndTime = null;
        for(CombinationProductRelation combinationProductRelation : combinationProductRelationList){
            //设置组合产品id
            combinationProductRelation.setCombinationProductId(combinationProduct.getId());
            //保存产品关联信息到数据库
            combinationProductRelationMapper.insert(combinationProductRelation);
            //保存产品消费点关联数据
            ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
            //设置消费点id
            consumeRelation.setConsumeId(combinationProductRelation.getConsumeId());
            //设置产品id为组合产品id
            consumeRelation.setProduct_id(productRelation.getId());
            POIOperation poiOperation = consumeSupplierApiService.getPOIById(combinationProductRelation.getConsumeId());
            if(poiOperation!=null){
                consumeRelation.setPoiId(poiOperation.getId());
            }

            //设置商户id 取product表的merchantId
            ProductRelation relationByTypeAndId = productRelationMapper.selectProductByTypeAndId(TICKET_PRODUCT,combinationProductRelation.getProductId());
            consumeRelation.setMerchantId(relationByTypeAndId.getMerchantId());
            productConsumeRelationMapper.insert(consumeRelation);
            totalPrice = totalPrice.add(combinationProductRelation.getSettlementPrice());
            if(combinationProductRelation.getIsRealName() !=null && combinationProductRelation.getIsRealName() ==1){
                isRealName = 1;
            }
            //获取有效期开始结束时间
            if(termOfValidityStartTime == null || termOfValidityStartTime.getTime() < combinationProductRelation.getTermOfValidityStartTime().getTime()){
                termOfValidityStartTime = combinationProductRelation.getTermOfValidityStartTime();
            }
            if(termOfValidityEndTime == null || termOfValidityEndTime.getTime() > combinationProductRelation.getTermOfValidityEndTime().getTime()){
                termOfValidityEndTime = combinationProductRelation.getTermOfValidityEndTime();
            }
        }
        //更新是否实名制字段
        combinationProduct.setIsRealName(isRealName);
        //更新组合产品有效期
        combinationProduct.setTermOfValidityStartTime(termOfValidityStartTime);
        combinationProduct.setTermOfValidityEndTime(termOfValidityEndTime);
        combinationProductMapper.updateCombinationProductByParam(combinationProduct);
        //更新公共产品实名制
        productRelation.setIsRealName(isRealName);
        productRelationMapper.updateProductByParam(productRelation);
        //保存组合产品价格
        CombinationProductPrice price = new CombinationProductPrice();
        price.setCombinationProductId(combinationProduct.getId());
        price.setSettlementPrice(totalPrice);
        combinationProductPriceMapper.insertUseGeneratedKeys(price);

        //设置公共产品id
        combinationProduct.setCommonProductId(productRelation.getId());
        combinationProductMapper.updateByPrimaryKeySelective(combinationProduct);

        distributorProductAssociationService.setCombinationToAllDistributor(productRelation,price.getSettlementPrice(),combinationProduct);

        //保存库存到redis和每日库存表
        if(UNLIMITED_STOCK.equals(combinationProduct.getStockMethod())){
            productStockService.saveUnlimitedProductStocks(combinationProduct.getCommonProductId(),combinationProduct.getProductNum(),combinationProduct.getTermOfValidityStartTime(),combinationProduct.getTermOfValidityEndTime());
        }else if(CYCLICAL_INVENTORY.equals(combinationProduct.getStockMethod())){
            productStockService.saveCombinationProductStocks(stocks,combinationProduct.getCommonProductId(),combinationProduct.getProductNum());
        }

        //如果组合产品没保存成功，抛出异常
        if(combinationProduct.getId() == null){
            throw new BusinessException(ResultCodeConstant.SERVICE_BUSSNISS_CODE,PRODUCT_SAVE_FAILURE);
        }
        rs.setId(String.valueOf(combinationProduct.getId()));
        return rs;
    }

    //组合产品复选框类型保存
    void saveVerificationCodeTypeAndCollocation(CombinationProduct combinationProduct){
        List<Dictionary> goodsSaleTypeList = baseDataFeign.getDicListMapByCode("VERIFYING_CODE_TYPE");
        List<String> dictionaryCode = goodsSaleTypeList.stream().map(Dictionary::getDicCode).collect(Collectors.toList());
        List<String> verificationCodeTypes = combinationProduct.getVerificationType();
        for(String dicCode:dictionaryCode){
            ProductValidateMethod validateMethod = new ProductValidateMethod();
            validateMethod.setProductType(COMBINATION_PRODUCT);
            validateMethod.setProductId(combinationProduct.getId());
            validateMethod.setDicCode(dicCode);
            if(verificationCodeTypes.contains(dicCode)){
                validateMethod.setState(DICTIONARY_STATUS_TRUE);
            }else {
                validateMethod.setState(DICTIONARY_STATUS_FALSE);
            }
            productValidateMethodMapper.insert(validateMethod);
        }

        //保存搭配产品复选框
        List<Dictionary> collocationProducts = baseDataFeign.getDicListMapByCode("COLLOCATION_PRODUCTS");
        List<String> collectionDictionaryCode = collocationProducts.stream().map(Dictionary::getDicCode).collect(Collectors.toList());
        List<String> collocationProductWeb = combinationProduct.getCollocationProduct();
        for(String dicCode:collectionDictionaryCode){
            CollocationProduct collocationProductInsert = new CollocationProduct();
            collocationProductInsert.setProductType(COMBINATION_PRODUCT);
            collocationProductInsert.setProductId(combinationProduct.getId());
            collocationProductInsert.setDicCode(dicCode);
            if(collocationProductWeb!=null && collocationProductWeb.size()!=0 && collocationProductWeb.contains(dicCode)){
                collocationProductInsert.setState(DICTIONARY_STATUS_TRUE);
            }else {
                collocationProductInsert.setState(DICTIONARY_STATUS_FALSE);
            }
            collocationProductMapper.insert(collocationProductInsert);
        }

    }

    /**
     * @ClassName: CombinationProductServiceImpl
     * @param combinationProduct
     * @param prices
     * @param stocks
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 更新组合产品
     * @CreateDate: Created in 2018/1/26 16:30
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED,rollbackFor=Exception.class)
    public ResultMessage updateCombinationProduct(CombinationProduct combinationProduct, List<CombinationProductPrice> prices,
                                                  List<CombinationProductStock> stocks) throws BusinessException{
        ResultMessage rs = new ResultMessage();
        int result = combinationProductMapper.updateCombinationProductByParam(combinationProduct);
        //修改复选框属性
        updateVerificationCodeTypeAndCollocation(combinationProduct);

        //保存组合产品价格
        if(prices!=null && prices.size()>0){
            for(CombinationProductPrice price:prices){
                combinationProductPriceMapper.updateByPrimaryKeySelective(price);
            }
        }

        //保存库存
        if(stocks!=null && stocks.size()>0){
            for (CombinationProductStock stock : stocks){
                if(stock.getId()!=null){
                    combinationProductStockMapper.updateStockByParam(stock);
                }else {
                    stock.setCombinationProductId(combinationProduct.getId());
                    combinationProductStockMapper.insertUseGeneratedKeys(stock);
                }
            }
        }

        //同步更新公共产品表
        ProductRelation relation = new ProductRelation();
        relation.setProductId(combinationProduct.getId());
        relation.setProductType(COMBINATION_PRODUCT);
        relation.setStockMethod(combinationProduct.getInstruction());
        relation.setRefundModel(combinationProduct.getRefundModel());
        productRelationMapper.updateProductByParam(relation);


        if(result <= 0){
            throw new BusinessException(ResultCodeConstant.SERVICE_BUSSNISS_CODE,PRODUCT_UPDATE_FAILURE);
        }

        CombinationProduct combinationProductDb = combinationProductMapper.selectByPrimaryKey(combinationProduct.getId());
        //保存库存到redis和每日库存表
        if (UNLIMITED_STOCK.equals(combinationProductDb.getStockMethod())) {
            productStockService.saveUnlimitedProductStocks(combinationProductDb.getCommonProductId(), combinationProductDb.getProductNum(),combinationProductDb.getTermOfValidityStartTime(),combinationProductDb.getTermOfValidityEndTime());
        } else if (CYCLICAL_INVENTORY.equals(combinationProduct.getStockMethod())) {
            productStockService.saveCombinationProductStocks(stocks, combinationProductDb.getCommonProductId(), combinationProductDb.getProductNum());
        }

        rs.setMessage(PRODUCT_UPDATE_SUCESS);
        return rs;
    }

    //修改验证方式复选框属性
    void updateVerificationCodeTypeAndCollocation(CombinationProduct combinationProduct){
        ProductValidateMethod validateMethod = new ProductValidateMethod();
        validateMethod.setProductId(combinationProduct.getId());
        validateMethod.setProductType(COMBINATION_PRODUCT);
        List<ProductValidateMethod> validateMethodDb = productValidateMethodMapper.selectValidateMethodByParam(validateMethod);
        List<String> validateMethodDbCode = validateMethodDb.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
        List<String> verificationCodeTypeWeb = combinationProduct.getVerificationType();
        if(verificationCodeTypeWeb!=null && verificationCodeTypeWeb.size()>0) {
            for (ProductValidateMethod productValidateMethodDb : validateMethodDb) {
                if (DICTIONARY_STATUS_TRUE.equals(productValidateMethodDb.getState())) {
                    if (!verificationCodeTypeWeb.contains(productValidateMethodDb.getDicCode())) {
                        productValidateMethodDb.setState(DICTIONARY_STATUS_FALSE);
                        productValidateMethodMapper.updateByParam(productValidateMethodDb);
                    }
                } else if (DICTIONARY_STATUS_FALSE.equals(productValidateMethodDb.getState())) {
                    if (verificationCodeTypeWeb.contains(productValidateMethodDb.getDicCode())) {
                        productValidateMethodDb.setState(DICTIONARY_STATUS_TRUE);
                        productValidateMethodMapper.updateByParam(productValidateMethodDb);
                    }
                }
            }
        }

        //搭配产品复选框
        CollocationProduct collocationProduct = new CollocationProduct();
        collocationProduct.setProductId(combinationProduct.getId());
        collocationProduct.setProductType(COMBINATION_PRODUCT);
        List<CollocationProduct> collocationProductDb = collocationProductMapper.selectCollocationProductByParam(collocationProduct);
        List<String> collocationDbCode = collocationProductDb.stream().map(CollocationProduct::getDicCode).collect(Collectors.toList());
        List<String> collocationWeb = combinationProduct.getCollocationProduct();
        if(collocationWeb!=null && collocationWeb.size()>0) {
            for (CollocationProduct collocation : collocationProductDb) {
                if (DICTIONARY_STATUS_TRUE.equals(collocation.getState())) {
                    if (!collocationWeb.contains(collocation.getDicCode())) {
                        collocation.setState(DICTIONARY_STATUS_FALSE);
                        collocationProductMapper.updateByParam(collocation);
                    }
                } else if (DICTIONARY_STATUS_FALSE.equals(collocation.getState())) {
                    if (collocationWeb.contains(collocation.getDicCode())) {
                        collocation.setState(DICTIONARY_STATUS_TRUE);
                        collocationProductMapper.updateByParam(collocation);
                    }
                }
            }
        }
    }

    /**
     * @ClassName: CombinationProductServiceImpl
     * @param id
     * @Return: com.cloud.drore.eboos.common.entity.supplier.vo.CombinationProductVo
     * @Decription: 根据id查询组合产品信息
     * @CreateDate: Created in 2018/1/18 14:50
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public CombinationProductVo selectCombinationProductById(Long id) throws BusinessException{
        //根据id查询组合产品信息
        CombinationProductVo combinationProductVo = combinationProductMapper.selectCombinationProductById(id);

        List<Long> consumeId = productConsumeRelationMapper.selectConsumeIdByProductId(combinationProductVo.getCommonProductId());
        List<ConsumeAndPoiNameVo> consumeAndPoiNameVoList = new ArrayList<>();
        for(Long consumeidChildren : consumeId){
            ConsumeAndPoiNameVo consumeAndPoiName = new ConsumeAndPoiNameVo();
            ConsumeOperation consume = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(consumeidChildren);
            if(consume !=null){
                //设置消费点名称和poi名称
                consumeAndPoiName.setPoiName(consume.getConsumePoiName());
                consumeAndPoiName.setConsumeName(consume.getConsumeName());
                consumeAndPoiNameVoList.add(consumeAndPoiName);
            }
        }
        combinationProductVo.setConsumeAndPoiNameVoList(consumeAndPoiNameVoList);

        //设置验证方式
        //子产品信息
        List<Long> productIds = combinationProductRelationMapper.selectProductIdByCombinationProductId(id);
        //验证类型
        List<String> validateMethodNames = new ArrayList<>();

        List<TicketAllVo> ticketAllVoList = new ArrayList();
        for(Long combinationId : productIds){
            TicketAllVo ticketAllVo = ticketMapper.selectTicketById(combinationId);
            if(ticketAllVo == null){
                continue;
            }

            //所属消费点
            ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
            //设置产品id为组合产品id
            consumeRelation.setProduct_id(ticketAllVo.getCommonProductId());
            List<ProductConsumeRelation> relations = productConsumeRelationMapper.selectRelationByParam(consumeRelation);
            if(relations != null && relations.size()>0){
                consumeRelation = (ProductConsumeRelation) relations.get(0);
                ConsumeOperation consumeOperation = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(consumeRelation.getConsumeId());
                if(consumeOperation!=null){
                    ticketAllVo.setConsumeName(consumeOperation.getConsumeName());
                }
            }

            //验证方式查询
            ProductValidateMethod productValidateMethod = new ProductValidateMethod();
            productValidateMethod.setProductId(ticketAllVo.getTicketId());
            productValidateMethod.setProductType(TICKET_PRODUCT);
            productValidateMethod.setState(DICTIONARY_STATUS_TRUE);
            List<ProductValidateMethod> validateMethodList = productValidateMethodMapper.selectValidateMethodByParam(productValidateMethod);
            List<String> validateMethodDbCode = validateMethodList.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
            validateMethodNames.addAll(validateMethodDbCode);
        }

        //验证方式去重
        Set validateMethodSet = new HashSet();
        validateMethodSet.addAll(validateMethodNames);
        validateMethodNames.clear();
        validateMethodNames.addAll(validateMethodSet);
        List<String> validateChNames = new ArrayList<>();
        for(String validateCode :validateMethodNames){
            DictionaryVo validMethod = baseDataFeign.getDictionaryVo(validateCode);
            if(validMethod!=null){
                validateChNames.add(validMethod.getName());
            }
        }
        combinationProductVo.setVerificationType(validateChNames);
        return combinationProductVo;
    }



    /**
     * @ClassName: CombinationProductServiceImpl
     * @param id
     * @Return: com.cloud.drore.eboss.supplier.entity.vo.CombProSupplierVo
     * @Decription: 根据id查询组合产品信息 供应商接口
     * @CreateDate: Created in 2018/1/25 16:43
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public CombProSupplierVo selectCombinationProductByIdSupplier(Long id){
        //根据id查询组合产品信息
        CombinationProduct combinationProduct = combinationProductMapper.selectAllColumnOfCombinationProduct(id);

        //字典code转换名称
        DictionaryVo paymentTypeDictionary = baseDataFeign.getDictionaryVo(combinationProduct.getPaymentType());
        if(paymentTypeDictionary!=null){
            combinationProduct.setPaymentType(paymentTypeDictionary==null?"":paymentTypeDictionary.getName());
        }

        //获取组合产品价格
        CombinationProductPrice combinationProductPrice = new CombinationProductPrice();
        combinationProductPrice.setCombinationProductId(id);
        List<CombinationProductPrice> productPriceList = combinationProductPriceMapper.selectPriceByParam(combinationProductPrice);
        //获取组合产品库存
        CombinationProductStock combinationProductStock = new CombinationProductStock();
        combinationProductStock.setCombinationProductId(id);
        List<CombinationProductStock> combinationProductStockList = combinationProductStockMapper.selectComProStockByParam(combinationProductStock);
        //封装到组合vo
        CombProSupplierVo combProSupplierVo = new CombProSupplierVo();

        //验证方式复选框数据查询
        setVerificationTypeAndCollocationProduct(combinationProduct);

        //子产品信息
        List<Long> productIds = combinationProductRelationMapper.selectProductIdByCombinationProductId(id);
        //验证类型
        List<String> validateMethodNames = new ArrayList<>();

        List<TicketAllVo> ticketAllVoList = new ArrayList();
        for(Long combinationId : productIds){
            TicketAllVo ticketAllVo = ticketMapper.selectTicketById(combinationId);
            if(ticketAllVo == null){
                continue;
            }

            //所属消费点
            ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
            //设置产品id为组合产品id
            consumeRelation.setProduct_id(ticketAllVo.getCommonProductId());
            List<ProductConsumeRelation> relations = productConsumeRelationMapper.selectRelationByParam(consumeRelation);
            if(relations != null && relations.size()>0){
                consumeRelation = (ProductConsumeRelation) relations.get(0);
                ConsumeOperation consumeOperation = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(consumeRelation.getConsumeId());
                if(consumeOperation!=null){
                    ticketAllVo.setConsumeName(consumeOperation.getConsumeName());
                }
            }

            //设置库存类型
            ticketAllVo.setProductType(TICKET_PRODUCT);
            if(StringUtils.isNotBlank(ticketAllVo.getStockMethod())){
                String stockMethod =baseDataFeign.getDictionaryVo(ticketAllVo.getStockMethod()).getName();
                ticketAllVo.setStockMethod(stockMethod==null?"":stockMethod);
            }
            //设置退订规则
            if(StringUtils.isNotBlank(ticketAllVo.getRefundModel())){
                String refundModel =baseDataFeign.getDictionaryVo(ticketAllVo.getRefundModel()).getName();
                ticketAllVo.setRefundModel(refundModel==null?"":refundModel);
            }
            //设置门票类型
            if(StringUtils.isNotBlank(ticketAllVo.getProductType())){
                String productType =baseDataFeign.getDictionaryVo(ticketAllVo.getProductType()).getName();
                ticketAllVo.setProductType(productType==null?"":productType);
            }

            //验证方式查询
            ProductValidateMethod productValidateMethod = new ProductValidateMethod();
            productValidateMethod.setProductId(ticketAllVo.getTicketId());
            productValidateMethod.setProductType(TICKET_PRODUCT);
            productValidateMethod.setState(DICTIONARY_STATUS_TRUE);
            List<ProductValidateMethod> validateMethodList = productValidateMethodMapper.selectValidateMethodByParam(productValidateMethod);
            List<String> validateMethodDbCode = validateMethodList.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
            validateMethodNames.addAll(validateMethodDbCode);

            if(ticketAllVo != null){
                ticketAllVoList.add(ticketAllVo);
            }
        }
        //验证方式去重
        Set validateMethodSet = new HashSet();
        validateMethodSet.addAll(validateMethodNames);
        validateMethodNames.clear();
        validateMethodNames.addAll(validateMethodSet);
        List<String> validateChNames = new ArrayList<>();
        for(String validateCode :validateMethodNames){
            DictionaryVo validMethod = baseDataFeign.getDictionaryVo(validateCode);
                if(validMethod!=null){
                    validateChNames.add(validMethod.getName());
                }
        }

        List<String> consumeList = new ArrayList<>();
        for(TicketAllVo ticketAllVo : ticketAllVoList){
            if(StringUtils.isNotBlank(ticketAllVo.getConsumeName())){
                consumeList.add(ticketAllVo.getConsumeName());
            }
        }
        if(consumeList !=null && consumeList.size()>0){
            combinationProduct.setConsumeNames(consumeList);
        }
        //设置验证类型
        combinationProduct.setVerificationType(validateChNames);
        combProSupplierVo.setCombinationProduct(combinationProduct);
        combProSupplierVo.setCombinationProductPrices(productPriceList);
        combProSupplierVo.setCombinationProductStocks(combinationProductStockList);

        combProSupplierVo.setTickets(ticketAllVoList);
        return combProSupplierVo;
    }

    //设置验证方式复选框数据到组合产品对象
    void setVerificationTypeAndCollocationProduct(CombinationProduct combinationProduct){

        //搭配产品复选框数据查询
        CollocationProduct collocationProduct = new CollocationProduct();
        collocationProduct.setProductId(combinationProduct.getId());
        collocationProduct.setProductType(COMBINATION_PRODUCT);
        collocationProduct.setState(DICTIONARY_STATUS_TRUE);
        List<CollocationProduct> collocationProductDb = collocationProductMapper.selectCollocationProductByParam(collocationProduct);
        List<String> collocationDbCode = collocationProductDb.stream().map(CollocationProduct::getDicCode).collect(Collectors.toList());
        List<String> collocationNames = new ArrayList<>();
        for(String collocation:collocationDbCode){
            collocation = baseDataFeign.getDictionaryVo(collocation).getName();
            collocationNames.add(collocation);
        }
        combinationProduct.setCollocationProduct(collocationNames);
    }

    /**
     * @ClassName: CombinationProductServiceImpl
     * @param id
     * @param status
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 更新产品状态
     * @CreateDate: Created in 2018/1/26 14:06
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage updateStatus(Long id,String status){
        ResultMessage rs = new ResultMessage();
        //设置门票id和上下架状态
        CombinationProduct combinationProduct = new CombinationProduct();
        combinationProduct.setId(id);
        combinationProduct.setStatus(status);
        //更新门票状态
        try {
            int i = combinationProductMapper.updateCombinationProductByParam(combinationProduct);
            ProductRelation relation = new ProductRelation();
            relation.setProductId(id);
            relation.setProductType(COMBINATION_PRODUCT);
            relation.setStatus(status);
            productRelationMapper.updateProductByParam(relation);
            //直接发布时保存库存到redis
            combinationProduct = combinationProductMapper.selectByPrimaryKey(id);
            if(THE_SHELVES.equals(status) && UNLIMITED_STOCK.equals(combinationProduct.getStockMethod())){
                productStockService.saveUnlimitedProductStocks(combinationProduct.getCommonProductId(),combinationProduct.getProductNum(),combinationProduct.getTermOfValidityStartTime(),combinationProduct.getTermOfValidityEndTime());
            }
        }catch (Exception e){
            rs.setMessage("产品状态更新失败!");
            rs.setIsSuccess(false);
            return rs;
        }

        rs.setMessage("产品状态更新成功!");
        return rs;
    }


    /**
     * @ClassName: CombinationProductServiceImpl
     * @param combinationId
     * @Return: java.util.List<com.cloud.drore.eboos.common.entity.supplier.vo.CombinationProductVo>
     * @Decription: 根据组合产品id查询子产品集合
     * @CreateDate: Created in 2018/2/1 10:43
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    public List<TicketAllVo> findProductByCombinationId(Long combinationId){
        ArrayList<TicketAllVo> ticketList = new ArrayList<>();
        List<Long> productId = combinationProductRelationMapper.selectProductIdByCombinationProductId(combinationId);
        for(Long id:productId){
            TicketAllVo ticketAllVo = ticketMapper.selectTicketById(id);
            if(ticketAllVo != null){
                DictionaryVo paymentTypeDictionary = baseDataFeign.getDictionaryVo(ticketAllVo.getPaymentType());
                DictionaryVo crowdDictionary = baseDataFeign.getDictionaryVo(ticketAllVo.getCrowd());
                if(paymentTypeDictionary!=null){
                    ticketAllVo.setPaymentType(paymentTypeDictionary==null?"":paymentTypeDictionary.getName());
                }
                if(crowdDictionary!=null){
                    ticketAllVo.setCrowd(crowdDictionary==null?"":crowdDictionary.getName());
                }

                //所属消费点
                ProductConsumeRelation consumeRelation = new ProductConsumeRelation();
                //设置产品id为组合产品id
                if(ticketAllVo.getCommonProductId() !=null){
                    consumeRelation.setProduct_id(ticketAllVo.getCommonProductId());
                    List<ProductConsumeRelation> relations = productConsumeRelationMapper.selectRelationByParam(consumeRelation);
                    if(relations !=null && relations.size()>0){
                        consumeRelation = relations.get(0);
                    }
                    ConsumeOperation consumeOperation = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(consumeRelation.getConsumeId());
                    if(consumeOperation!=null){
                        ticketAllVo.setConsumeName(consumeOperation.getConsumeName());
                        ticketAllVo.setPoiName(consumeOperation.getConsumePoiName());
                        ticketAllVo.setPoiId(consumeOperation.getConsumePoiId());
                    }
                }
                ticketAllVo.setConsumeId(consumeRelation.getConsumeId());

                ticketList.add(ticketAllVo);
            }
        }
        return ticketList;
    }


    /**
     * @ClassName: CombinationProductServiceImpl
     * @param id
     * @param status
     * @param rejectReason
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 驳回组合产品
     * @CreateDate: Created in 2018/2/1 15:50
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage rejectProduct(Long id, String status,String rejectReason) {
        ResultMessage rs = new ResultMessage();
        //驳回组合产品
        try {
            Long commonId = productRelationMapper.selectIdByTypeAndId(COMBINATION_PRODUCT,id);
            Long userId = Long.valueOf(LocalData.getCurrentUser().getTypeId());
            int i = combinationProductMapper.rejectProduct(id,status);
            ProductRejectInfo productRejectInfo = new ProductRejectInfo();
            productRejectInfo.setRejectUserId(userId);
            productRejectInfo.setRejectReason(rejectReason);
            productRejectInfo.setRejectTime(new Date());
            productRejectInfo.setCommonProductId(commonId);
            //保存驳回信息
            productRejectInfoMapper.insert(productRejectInfo);

            //更新公共表状态
            ProductRelation relation = new ProductRelation();
            relation.setProductId(id);
            relation.setProductType(TICKET_PRODUCT);
            relation.setStatus(status);
            productRelationMapper.updateProductByParam(relation);
        }catch (Exception e){
            rs.setMessage("更新失败!");
            rs.setIsSuccess(false);
            return rs;
        }
        rs.setMessage("更新成功!");
        return rs;
    }


    /**
     * @ClassName: CombinationProductServiceImpl
     * @param pagePo
     * @Return: com.github.pagehelper.PageInfo
     * @Decription: 分页查询组合产品接口
     * @CreateDate: Created in 2018/3/6 10:10
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public PageInfo findCombinationProductByParam(PagePo<CombinationProductQueryPo> pagePo) throws BusinessException{

        Date date3 = new Date();
        CombinationProductQueryPo productQueryPo = pagePo.getFields();
        if(productQueryPo == null){
            throw new BusinessException(ResultCodeConstant.SERVICE_BUSSNISS_CODE,"参数不能为空!");
        }
        //查询消费点集合
        POIOperation poiOperation = new POIOperation();
        poiOperation.setId(productQueryPo.getPoiId());
        List<ConsumeOperation> consumeOperationList = (List<ConsumeOperation>) consumeSupplierApiService.findConsumeList(poiOperation).getData();
        if(LocalData.getCurrentUser().getTypeId() !=-1 ){
            productQueryPo.setSupplierId(Long.valueOf(LocalData.getCurrentUser().getTypeId()));
        }
        pagePo.setFields(productQueryPo);
        //根据门票po查询门票数据
        PageHelper.startPage(pagePo.getPageNum(),pagePo.getPageSize());
        List<CombinationProductVo> combinationProductVoList = combinationProductMapper.findCombinationProductByParamAndPoi(pagePo.getFields());
        Date date1 = new Date();

        List<CombinationProductVo> resultList = combinationProductVoList.stream().map(combinationProductVo -> {
            List<Long> consumeId = productConsumeRelationMapper.selectConsumeIdByProductId(combinationProductVo.getCommonProductId());
            //设置产品人群库存状态
            DictionaryVo crowdDictionary = baseDataFeign.getDictionaryVo(combinationProductVo.getProductCrowd());
            if(crowdDictionary!=null){
                combinationProductVo.setProductCrowd(crowdDictionary.getName());
            }
            DictionaryVo stockMethodDictionary = baseDataFeign.getDictionaryVo(combinationProductVo.getStockMethod());
            if(stockMethodDictionary!=null){
                combinationProductVo.setStockMethod(stockMethodDictionary.getName());
            }

            List<ConsumeAndPoiNameVo> consumeAndPoiNameVoList = new ArrayList<>();
            for(Long id : consumeId){
                ConsumeAndPoiNameVo consumeAndPoiName = new ConsumeAndPoiNameVo();

                //从集合中查出对应消费点对象
                List<ConsumeOperation> operationList = consumeOperationList.stream().filter(consumeOperation -> {
                    return consumeOperation.getId() == id;
                }).collect(Collectors.toList());

                if(operationList!=null && operationList.size()>0){
                    //设置属性到对象中
                    ConsumeOperation consume = (ConsumeOperation) operationList.get(0);
                    consumeAndPoiName.setPoiName(consume.getConsumePoiName());
                    consumeAndPoiName.setConsumeName(consume.getConsumeName());
                    consumeAndPoiNameVoList.add(consumeAndPoiName);
                }

            }
            combinationProductVo.setConsumeAndPoiNameVoList(consumeAndPoiNameVoList);

            //是否实名制标识,默认不实名
//            int real_name_flag = 1;
//            List<Ticket> tickets = combinationProductRelationMapper.selectTicketInfoByCombinationProductId(Long.valueOf(combinationProductVo.getId()));
//            if(tickets!=null && tickets.size()!=0){
//                for(Ticket ticket:tickets){
//                    if(ticket!=null &&ticket.getIsRealName()!=null && ticket.getIsRealName()==0){
//                        real_name_flag = 0;
//                    }
//                }
//                combinationProductVo.setIsRealName(real_name_flag);
//            }

            return combinationProductVo;
        }).collect(Collectors.toList());

        Date date2 = new Date();
        System.out.println(date2.getTime()-date1.getTime());

        Date date4 = new Date();
        System.out.println("总时间：----"+(date4.getTime()-date3.getTime()));

        PageInfo pageInfo = new PageInfo(combinationProductVoList);
        return pageInfo;
    }


    /**
     * @ClassName: CombinationProductServiceImpl
     * @param pagePo
     * @Return: com.github.pagehelper.PageInfo
     * @Decription: 提供分销商分页查询接口
     * @CreateDate: Created in 2018/3/6 10:03
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public PageInfo findCombinationProductByParamDealer(PagePo<CombinationProductQueryPo> pagePo) throws BusinessException{

        CombinationProductQueryPo productQueryPo = pagePo.getFields();
        if(productQueryPo == null){
            throw new BusinessException(ResultCodeConstant.SERVICE_BUSSNISS_CODE,"参数不能为空!");
        }
        //查询消费点集合
        POIOperation poiOperation = new POIOperation();
        poiOperation.setId(productQueryPo.getPoiId());
        List<ConsumeOperation> consumeOperationList = (List<ConsumeOperation>) consumeSupplierApiService.findConsumeList(poiOperation).getData();
        //设置状态为已上架
        productQueryPo.setStatus(THE_SHELVES);
        pagePo.setFields(productQueryPo);
        //根据门票po查询门票数据
        PageHelper.startPage(pagePo);
        List<CombinationProductVo> combinationProductVoList = combinationProductMapper.findCombinationProductByParamAndPoi(pagePo.getFields());

        List<CombinationProductVo> resultList = combinationProductVoList.stream().map(combinationProductVo -> {

            List<Long> consumeId = productConsumeRelationMapper.selectConsumeIdByProductId(combinationProductVo.getCommonProductId());
            //设置产品人群库存状态
            DictionaryVo crowdDictionary = baseDataFeign.getDictionaryVo(combinationProductVo.getProductCrowd());
            if(crowdDictionary!=null){
                combinationProductVo.setProductCrowd(crowdDictionary.getName());
            }
            DictionaryVo stockMethodDictionary = baseDataFeign.getDictionaryVo(combinationProductVo.getStockMethod());
            if(stockMethodDictionary!=null){
                combinationProductVo.setStockMethod(stockMethodDictionary.getName());
            }

            List<ConsumeAndPoiNameVo> consumeAndPoiNameVoList = new ArrayList<>();
            for(Long id : consumeId){
                ConsumeAndPoiNameVo consumeAndPoiName = new ConsumeAndPoiNameVo();

                //从集合中查出对应消费点对象
                List<ConsumeOperation> operationList = consumeOperationList.stream().filter(consumeOperation -> {
                    return consumeOperation.getId() == id;
                }).collect(Collectors.toList());

                if(operationList!=null && operationList.size()>0){
                    //设置属性到对象中
                    ConsumeOperation consume = (ConsumeOperation) operationList.get(0);
                    consumeAndPoiName.setPoiName(consume.getConsumePoiName());
                    consumeAndPoiName.setConsumeName(consume.getConsumeName());
                    consumeAndPoiNameVoList.add(consumeAndPoiName);
                }

            }
            combinationProductVo.setConsumeAndPoiNameVoList(consumeAndPoiNameVoList);

            //是否实名制标识,默认不实名
//            int real_name_flag = 1;
//            List<Ticket> tickets = combinationProductRelationMapper.selectTicketInfoByCombinationProductId(Long.valueOf(combinationProductVo.getId()));
//            if(tickets!=null && tickets.size()!=0){
//                for(Ticket ticket:tickets){
//                    if(ticket!=null &&ticket.getIsRealName()!=null && ticket.getIsRealName()==0){
//                        real_name_flag = 0;
//                    }
//                }
//                combinationProductVo.setIsRealName(real_name_flag);
//            }

            //验证类型
            List<String> validateMethodNames = new ArrayList<>();
            //验证方式查询
            ProductValidateMethod productValidateMethod = new ProductValidateMethod();
            productValidateMethod.setProductId(combinationProductVo.getId());
            productValidateMethod.setProductType(COMBINATION_PRODUCT);
            productValidateMethod.setState(DICTIONARY_STATUS_TRUE);
            List<ProductValidateMethod> validateMethodList = productValidateMethodMapper.selectValidateMethodByParam(productValidateMethod);
            List<String> validateMethodDbCode = validateMethodList.stream().map(ProductValidateMethod::getDicCode).collect(Collectors.toList());
            validateMethodNames.addAll(validateMethodDbCode);
            combinationProductVo.setVerificationType(validateMethodNames);
            return combinationProductVo;
        }).collect(Collectors.toList());

        PageInfo pageInfo = new PageInfo(combinationProductVoList);
        return pageInfo;
    }


    /**
     * @ClassName: CombinationProductServiceImpl
     * @param pagePo
     * @Return: com.github.pagehelper.PageInfo
     * @Decription: 供应商组合产品查询
     * @CreateDate: Created in 2018/3/6 10:16
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public PageInfo findCombinationProductByParamSupplier(PagePo<CombinationProductQueryPo> pagePo) throws BusinessException{

        CombinationProductQueryPo productQueryPo = pagePo.getFields();
        if(productQueryPo == null){
            throw new BusinessException(ResultCodeConstant.SERVICE_BUSSNISS_CODE,"参数不能为空!");
        }
        //查询消费点集合
        POIOperation poiOperation = new POIOperation();
        poiOperation.setId(productQueryPo.getPoiId());
        List<ConsumeOperation> consumeOperationList = (List<ConsumeOperation>) consumeSupplierApiService.findConsumeList(poiOperation).getData();
        //查询有当前供应商参与的组合产品
        productQueryPo.setSupplierId(Long.valueOf(LocalData.getCurrentUser().getTypeId()));
        pagePo.setFields(productQueryPo);
        //根据门票po查询门票数据
        PageHelper.startPage(pagePo);
        List<CombinationProductVo> combinationProductVoList = combinationProductMapper.findCombinationProductByParamAndPoiSupplier(pagePo.getFields());

        List<CombinationProductVo> resultList = combinationProductVoList.stream().map(combinationProductVo -> {

            List<Long> consumeId = productConsumeRelationMapper.selectConsumeIdByProductId(combinationProductVo.getCommonProductId());
            //设置产品人群库存状态
            DictionaryVo crowdDictionary = baseDataFeign.getDictionaryVo(combinationProductVo.getProductCrowd());
            if(crowdDictionary!=null){
                combinationProductVo.setProductCrowd(crowdDictionary.getName());
            }

            List<ConsumeAndPoiNameVo> consumeAndPoiNameVoList = new ArrayList<>();
            for(Long id : consumeId){
                ConsumeAndPoiNameVo consumeAndPoiName = new ConsumeAndPoiNameVo();

                //从集合中查出对应消费点对象
                List<ConsumeOperation> operationList = consumeOperationList.stream().filter(consumeOperation -> {
                    return consumeOperation.getId() == id;
                }).collect(Collectors.toList());

                if(operationList!=null && operationList.size()>0){
                    //设置属性到对象中
                    ConsumeOperation consume = (ConsumeOperation) operationList.get(0);
                    consumeAndPoiName.setPoiName(consume.getConsumePoiName());
                    consumeAndPoiName.setConsumeName(consume.getConsumeName());
                    consumeAndPoiNameVoList.add(consumeAndPoiName);
                }

            }
            combinationProductVo.setConsumeAndPoiNameVoList(consumeAndPoiNameVoList);

            return combinationProductVo;
        }).collect(Collectors.toList());

        PageInfo pageInfo = new PageInfo(combinationProductVoList);
        return pageInfo;
    }


    /**
     * @ClassName: CombinationProductServiceImpl
     * @param
     * @Return: void
     * @Decription: 更新已过期的组合产品状态
     * @CreateDate: Created in 2018/4/12 11:51
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    public void updateExpiredCombinationProduct(){
        CombinationProduct combinationProduct = new CombinationProduct();
        ProductRelation relation = new ProductRelation();
        List<CombinationProductVo> combinationProductVos = combinationProductMapper.selectExpiredCombinationProduct();
        for (CombinationProductVo combinationProductVo : combinationProductVos ){
            combinationProduct.setId(combinationProductVo.getId());
            combinationProduct.setStatus(EXPIRED);
            //更新门票状态
            try {
                int i = combinationProductMapper.updateCombinationProductByParam(combinationProduct);
                relation.setProductId(combinationProductVo.getId());
                relation.setProductType(COMBINATION_PRODUCT);
                relation.setStatus(EXPIRED);
                productRelationMapper.updateProductByParam(relation);
             }catch (Exception e){
                log.error(e.getLocalizedMessage());
            }
        }
    }

    /**
     * @ClassName: CombinationProductServiceImpl
     * @param pagePo
     * @Return: com.github.pagehelper.PageInfo
     * @Decription:
     * @CreateDate: Created in 2018/4/13 17:31
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public PageInfo findTicketByParamWithoutExpired(PagePo<TicketQueryPo> pagePo) throws BusinessException {
        return new PageInfo(findTicketListWithoutExpired(pagePo));
    }


    private List<TicketAllVo> findTicketListWithoutExpired(PagePo<TicketQueryPo> pagePo) throws BusinessException {
        //根据门票po查询门票数据
        PageHelper.startPage(pagePo);
        List<TicketAllVo> ticketList = ticketMapper.findTicketListWithoutExpired(pagePo.getFields());
        //设置消费点名称和poi名称
        ticketList.stream().map(ticketStream -> {
            ConsumeOperation consume = (ConsumeOperation) consumeSupplierApiService.selectByPrimaryKey(ticketStream.getConsumeId());
            if (consume != null) {
                ticketStream.setConsumeName(consume.getConsumeName());
                ticketStream.setPoiName(consume.getConsumePoiName());
                if (StringUtils.isNotBlank(ticketStream.getCrowd())) {
                    DictionaryVo crowdDic = baseDataFeign.getDictionaryVo(ticketStream.getCrowd());
                    ticketStream.setCrowd(crowdDic == null ? "" : crowdDic.getName());
                }
                if (StringUtils.isNotBlank(ticketStream.getStockMethod())) {
                    DictionaryVo stockDic = baseDataFeign.getDictionaryVo(ticketStream.getStockMethod());
                    ticketStream.setStockMethod(stockDic == null ? "" : stockDic.getName());
                }
            }
            if (ticketStream.getRefundModel() != null) {
                DictionaryVo refundDictionary = baseDataFeign.getDictionaryVo(ticketStream.getRefundModel());
                if (refundDictionary != null) {
                    ticketStream.setRefundModel(refundDictionary.getName());
                }
            }

            //设置产品类型为门票类型
            ticketStream.setProductType(TICKET_PRODUCT_CH_NAME);
            return ticketStream;
        }).collect(Collectors.toList());
        return ticketList;
    }


    /**
     * @ClassName: CombinationProductServiceImpl
     * @param
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage<com.cloud.drore.eboss.supplier.entity.Product>
     * @Decription: 查询全部公共产品
     * @CreateDate: Created in 2018/4/13 18:29
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage<ProductRelation> findAllProduct() throws BusinessException {
        ResultMessage resultMessage = new ResultMessage();
        List<ProductRelation> products = productRelationMapper.findProductWithOutExpired();
        //截取前30个
        if(products.size()>30){
            products.subList(0,30);
        }
        resultMessage.setData(products);
        return resultMessage;
    }

    /**
     * @ClassName: CombinationProductServiceImpl
     * @param
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 获取字典信息初始化接口
     * @CreateDate: Created in 2018/1/26 14:50
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    @Override
    public ResultMessage init(){
        DictionaryTicketVo dictionaryTicket = new DictionaryTicketVo();
        //获取产品类型字典信息
        dictionaryTicket.setDictionaryProductType(baseDataFeign.getDicListMapByCodeVo("PRODUCT_TYPE"));
        //获取库存方式字典信息
        dictionaryTicket.setDictionaryStockMethod(baseDataFeign.getDicListMapByCodeVo("INVENTORY_MODE"));
        //获取支付类型字典信息
        dictionaryTicket.setDictionaryPaymentType(baseDataFeign.getDicListMapByCodeVo("PAYMENT_TYPE"));
        //获取产品人群字典信息
        dictionaryTicket.setDictionaryProductCrowd(baseDataFeign.getDicListMapByCodeVo("PRODUCT_CROWD"));
        //获取退款模式字典信息
        dictionaryTicket.setDictionaryRefundModel(baseDataFeign.getDicListMapByCodeVo("REFUND_MODEL"));
        //获取退款手续费字典信息
        dictionaryTicket.setDictionaryRefundFormalities(baseDataFeign.getDicListMapByCodeVo("REFUND_FORMALITIES"));
        //获取验证方式字典信息
        dictionaryTicket.setDictionaryVerifyingCodeType(baseDataFeign.getDicListMapByCodeVo("VERIFYING_CODE_TYPE"));
        //获取产品状态字典信息
        dictionaryTicket.setDictionaryProductStatus(baseDataFeign.getDicListMapByCodeVo("PRODUCT_STATUS"));
        //获取产品状态字典信息
        dictionaryTicket.setCollocationProducts(baseDataFeign.getDicListMapByCodeVo("COLLOCATION_PRODUCTS"));
        //poi列表信息
        dictionaryTicket.setPoiOperation((List<POIOperation>) ipoiSupplierApiService.findByName().getData());
        return new ResultMessage(dictionaryTicket);
    }

}